//
//  BaseViewController.m
//  CarUser
//
//  Created by 王森林 on 2018/11/30.
//  Copyright © 2018年 王森林. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()
@property (nonatomic, strong) UIView *noDataView;
@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = Common_BackgroundColor;
    [self setNavStyle];
    [self setLeftBcakBtn];
    // Do any additional setup after loading the view.
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}


- (void)setLeftBcakBtn{
    if (self.navigationController.viewControllers.count > 1) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    }
}

//设置导航栏风格
- (void)setNavStyle
{
    self.view.backgroundColor = Common_BackgroundColor;
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    [self.navigationController.navigationBar setCustomBgColor:Common_NavigroundColor];
    [self.navigationController.navigationBar setBackgroundColor:UIColor.clearColor];
//    [self.navigationController.navigationBar setBackgroundImage:Common_NavBgImgv forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];

    self.navigationController.navigationBar.alpha = 1;
    self.navigationController.navigationBar.translucent = NO;
    self.extendedLayoutIncludesOpaqueBars = YES;

    //设置导航栏标题和返回键的颜色和字体
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [[UINavigationBar appearance] setTintColor:UIColor.whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
}

/**
 自定义右导航栏按钮（方法先放这，并不一定要使用）
 
 @param title 标题
 @param selector 方法
 */
- (void)setNaviDefaultRightBtnWithTitle:(NSString *)title andSel:(SEL)selector{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
//    CGSize titleSize = [title sizeWithFont:FONT_SIZE(12) constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    NSDictionary *attr=@{NSFontAttributeName:FONT_SIZE(12)};
    CGSize titleSize = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context: nil].size;
    btn.frame = CGRectMake(5, 0, titleSize.width, 20);
    btn.titleLabel.font = FONT_SIZE(12);
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:Common_TextColor forState:UIControlStateHighlighted];
    [btn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
}





- (void)backAction{
    [self.view endEditing:YES];
//    [BSNLUtil hideHud:self.view];
//    [BSNLUtil hideHud:self.navigationController.view];
//    GetAppDelegate;
//    [appDelegate.window endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
  
}


- (void)showNodataView:(float)Y withView:(nonnull UIView *)parentView
{
    [self.noDataView removeFromSuperview];
    UIImage *nodataImage =IMG(@"nodataimage");
    [parentView addSubview:self.noDataView];
    self.noDataView.frame = CGRectMake(0,Y , BOUNDWIDTH, IMGHEIGHT(nodataImage)+40);
 
    UIImageView *nodataImageView = [UIImageView new];
    nodataImageView.image = nodataImage;
    [self.noDataView addSubview:nodataImageView];
    nodataImageView.frame = CGRectMake((BOUNDWIDTH - IMGWIDTH(nodataImage))/2, 0, IMGWIDTH(nodataImage), IMGHEIGHT(nodataImage));
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.frame  = CGRectMake(0,IMGHEIGHT(nodataImage)+10 , BOUNDWIDTH, 20);
    titleLabel.text = @"这里什么都没有～";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_SIZE(13);
    titleLabel.textColor = Common_TextLowColor;
    [self.noDataView addSubview:titleLabel];
    
}

- (void)hideNoDataView
{
   
    [self.noDataView removeFromSuperview];
     self.noDataView = nil;
    
}


-(UIView *)noDataView
{
    if (!_noDataView) {
        _noDataView = [UIView new];
    }
    return _noDataView;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
